package com.anxin.registerManagement.controller;

import com.anxin.registerManagement.log.Log;
import com.anxin.registerManagement.service.FileService;
import com.anxin.registerManagement.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 叶前呈
 * @date 2022/3/26 20:02
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    @Log("上传头像")
    @PostMapping("/uploadImage")
    public ResultUtil uploadImage(@RequestParam("file") MultipartFile multipartFile, @RequestParam("jwt") String jwt) throws IOException {
        // TODO:这里不加权限限制，在service层进行过滤
        fileService.uploadImage(multipartFile,jwt);
        return ResultUtil.success();
    }

    @GetMapping("/getPhoto")
    public ResultUtil getPhoto(HttpServletRequest request){
        return ResultUtil.success(fileService.getPhoto(request));
    }

}
